package com.example.d_app;

import android.content.Context;
import android.content.SharedPreferences;

public class User {
    private String name="";
    private String pwd="";
    private String phone="";
    private String add="";
    private Boolean flag=false;

    public Boolean getFlag() {
        return flag;
    }

    public void setFlag(Boolean flag) {
        this.flag = flag;
    }

    //存储文件名
    private  static  final  String SHARED_NAME="userInfo";




    //SharedPreferences方法
    //存储文件在data/data/com.example.demo1/shared_prefs
    SharedPreferences sharedPreferences;

    public  void saveUserBySharedPreferences(Context context) {

        sharedPreferences = context.getSharedPreferences(SHARED_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("name",name);
        editor.putString("pwd",pwd);
        editor.putString("phone",phone);
        editor.putString("add",add);
        editor.putBoolean("flag",flag);
        editor.commit();
    }

    public void getUserBySharedPreferences(Context context){
        sharedPreferences = context.getSharedPreferences(SHARED_NAME, Context.MODE_PRIVATE);
        name=sharedPreferences.getString("name","");
        pwd=sharedPreferences.getString("pwd","");
        phone=sharedPreferences.getString("phone","");
        add=sharedPreferences.getString("add","");
        flag=sharedPreferences.getBoolean("flag",false);

    }






    public User() {
    }

    public User(String name, String pwd, String phone, String add, Boolean flag) {
        this.name = name;
        this.pwd = pwd;
        this.phone = phone;
        this.add = add;
        this.flag = flag;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAdd() {
        return add;
    }

    public void setAdd(String add) {
        this.add = add;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }


}
